package com.arvato;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.Date;
import java.util.concurrent.TimeoutException;

/**
 * @Author wangjian (jian.wang@bertelsmann.com.cn)
 * @Date 2016/11/23 10:45
 */
public class Send {


        public final static String EXCHANGE_NAME = "spring-boot-exchange";

        public static void main(String[] args) throws IOException, TimeoutException, InterruptedException {
            /**
             * 配置amqp broker 连接信息
             */
            ConnectionFactory factory = new ConnectionFactory();
            factory.setUsername("rabbitadmin");
            factory.setPassword("123456");
            factory.setVirtualHost("rabbithost");
            factory.setHost("192.168.8.128");


            Connection connection = factory.newConnection();
            Channel channel = connection.createChannel();
            // 声明转发器和类型
            channel.exchangeDeclare(EXCHANGE_NAME, "direct",true);
            channel.queueDeclare( "queue" , true, false, false, null) ;
            String message = new Date().toString()+" : log something";
            // 往转发器上发送消息
            channel.basicPublish(EXCHANGE_NAME, "", null, message.getBytes());

            System.out.println(" [x] Sent '" + message + "'");

            channel.close();
            connection.close();
        }


}
